<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>用户信息管理</title>
<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
<link rel="stylesheet" type="text/css" href="../../css/css.css"/>
<link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.4.3/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="../../css/colorReset.css"/>



<style type="text/css">
.popup_con {
	border: 1px solid #95B8E7;
	width: 380px;
	margin: 10px auto 0 auto;
}

.popup_con ul {
	margin: 10px auto;
	width: 380px;
	overflow: hidden;
}

.popup_con ul li {
	width: 340px;
	display: block;
	float: left;
	height: 25px;
	overflow: hidden;
	padding: 5px 0;
}

.popup_con ul li.li_col {
	width: 380px;
	height: auto;
}

.popup_con .text {
	width: 200px;
}

.tree_con {
	height: 270px;
	overflow: auto;
	margin: 0 auto;
	padding-top: 5px;
}

#system_show .tree_con {
	height: 305px;
}

.search-con {
	width: 100%;;
	background: #f0fbff;
	border-bottom: 1px solid #d1d8de;
	padding: 5px 0;
	margin: 0;
	line-height: 26px;
}

.search-con .text {
	width: 110px;
	height: 20px;
	line-height: 20px;
	border-radius: 0;
}

.search-con button {
	display: inline;
}

input[readonly='readonly'] {
	background: #fff;
}

.data_con {
	width: 100%;
}

.input_con .text {
	width: 185px;
}

.passwordStrength {
	float: left;
	width: 193px;
	margin-left: 90px;
	color: #fff;
	font-size: 12px;
	margin-bottom: 0px;
	padding-top: 3px;
}

.passwordStrength>span {
	float: left;
	width: 63px;
	height: 8px;
	max-width: 120px;
	margin-left: 1px;
	text-align: center;
	background: #ccc;
}

.passwordStrength>span.first.bgStrength {
	background: #FC7272;
}

.passwordStrength>span.second.bgStrength {
	background: #FCC072;
}

.passwordStrength>span.last.bgStrength {
	background: #79D00D;
}
</style>

</head>

<body>

	<div class="main">
		<!-- 检索区域开始 -->
		<div class="sel_div">
			<table cellpadding="0" cellspacing="0" class="sel_con">
				<tr>
					<th colspan="5">数据检索</th>
				</tr>
				<tr>
					<td><label>所属公司：</label> <input class="text" type="text"
						name="comboxSearchCompany" id="comboxSearchCompany" /></td>
					<td><label>所属部门：</label> <input class="text" type="text"
						name="comboxSearchDepartment" id="comboxSearchDepartment" /></td>
					<td><label>注册时间：</label> <input type="text"
						name="txtCreateTimeBeg" id="txtCreateTimeBeg"
						class="text easyui-datetimebox" editable="false"
						validType="dateValid['#txtCreateTimeBeg','#txtCreateTimeEnd']" />
					</td>
					<td><label style="width: 23px; text-align: left">到</label> <input
						id="txtCreateTimeEnd" name="txtCreateTimeEnd"
						class="text easyui-datetimebox" editable="false"
						validType="dateValid['#txtCreateTimeBeg','#txtCreateTimeEnd']" />
					</td>
					<td rowspan="1">
						<button class="query_btn easyui-linkbutton" iconCls="icon-search"
							onclick="onSearch()">查询</button>
					</td>
				</tr>
				<tr>
					<td><label>邮箱地址：</label> <input class="text" type="text"
						name="txtEmail" id="txtEmail" /></td>
					<td><label>用户姓名：</label> <input id="txtUserName"
						name="txtUserName" class="text" /></td>

					<td><label>授权状态：</label> <input class="text" type="text"
						name="comboxSearchAuthState" id="comboxSearchAuthState" /></td>
					<td>&nbsp;</td>
					<td rowspan="1">
						<button class="query_btn easyui-linkbutton" iconCls="icon-reset"
							onclick="onReset()">重置</button>
					</td>
				</tr>
			</table>
		</div>

		<!-- 检索区域结束 -->
		<div class="data_con">
			<div id="toolbox" style="padding: 5px; height: 25px">
				<div style="margin-bottom: 5px; float: left">
					<a href="javascript:void(0)" onclick="onAdd()"
						class="easyui-linkbutton" id="toolbar_add" iconCls="icon-add"
						plain="true">新增</a> <a href="javascript:void(0)"
						onclick="onUpdate()" class="easyui-linkbutton" id="toolbar_modify"
						iconCls="icon-edit" plain="true">修改</a> <a
						href="javascript:void(0)" onclick="onDel()"
						class="easyui-linkbutton" id="toolbar_delete"
						iconCls="icon-remove" plain="true">刪除</a> <a
						href="javascript:void(0)" onclick="setEnable()"
						class="easyui-linkbutton" id="toolbar_start" iconCls="icon-more"
						plain="true">启用/停用</a> <a href="javascript:void(0)"
						onclick="import_link()" class="easyui-linkbutton"
						id="toolbar_import" iconCls="icon-undo" plain="true">导入</a>
				</div>
			</div>
			<table id="datagrid" style="height: 300px"
				data-options="fitColumns:true,toolbar:'#toolbox'">
			</table>
		</div>
	</div>
	<div id="winEdit" class="easyui-window" title="用户信息管理-新增"
		style="width: 730px; height: auto; top: 20px"
		data-options="iconCls:'icon-save',modal:true,minimizable:false,maximizable:false,collapsible:false">
		<form id="userForm" method="post">
			<div class="popup_con">
				<ul>
					<li><label for="userCode" class="label">账号：</label>
						<div class="input_con">
							<input id="userCode" name="userCode"
								class="easyui-validatebox text" tabindex="1"
								data-options="required:true,validType:'username'"
								missingMessage="账号不能为空，且以字母开头，允许1-16字节，允许字母数字下划线"
								invalidMessage="账号不合法（字母开头，允许1-16字节，允许字母数字下划线）" />
						</div></li>
					<li><label for="roleId" class="label">所属角色：</label>
						<div class="input_con">
							<input type="text" name="roleId" id="roleId" class="text"
								tabindex="8" />
						</div></li>
					<li style="height: 33px;"><label for="password" class="label">密码：</label>
						<div class="input_con">
							<input id="password" name="password" plugin="passwordStrength"
								type="password" class="easyui-validatebox text" tabindex="2"
								data-options="required:true,validType:'maxLength[117]'"
								missingMessage="密码不能为空！" maxlength="117" />
						</div>
						<div class="passwordStrength">
							<span class="first"></span> <span class="second"></span> <span
								class="last"></span>
						</div></li>
					<li style="height: 33px;"><label for="confirmPassword"
						class="label">确认密码：</label>
						<div class="input_con">
							<input id="confirmPassword" name="confirmPassword"
								type="password" class="easyui-validatebox text" tabindex="3"
								data-options="required:true" validType="equalTo['#password']"
								missingMessage="确认密码不能为空！" />
						</div></li>
					<li><label for="userName" class="label">姓名：</label>
						<div class="input_con">
							<input id="userName" name="userName"
								class="easyui-validatebox text" tabindex="4"
								data-options="required:true,validType:'length[1,10]'"
								missingMessage="姓名不能为空，且10个字符以内！" />
						</div></li>
					<li><label for="comboxAuthState" class="label">授权状态：</label>
						<div class="input_con">
							<input type="text" name="comboxAuthState" id="comboxAuthState"
								class="text" tabindex="9" style="width: 70px;" />
						</div> <label for="loginStatus" class="label" style="width: 65px;">登陆限制：</label>
						<div class="input_con">
							<input type="text" name="loginStatus" id=loginStatus class="text"
								tabindex="10" style="width: 60px;" />
						</div></li>
					<li><label for="phoneNumber" class="label">电话：</label>
						<div class="input_con">
							<input class="easyui-validatebox text" type="text"
								name="phoneNumber" id="phoneNumber" tabindex="5"
								data-options="required:true,validType:'phone'"
								missingMessage="请输入正确格式的电话号码，如020-88888888,15888888888" />
						</div></li>
					<li><label for="companyCode" class="label">所属公司：</label>
						<div class="input_con">
							<input type="text" name="companyCode" id="companyCode"
								class="text" tabindex="11" />
						</div></li>
					<li><label for="emailAddress" class="label">邮箱：</label>
						<div class="input_con">
							<input class="easyui-validatebox text" type="text"
								name="emailAddress" id="emailAddress" tabindex="6"
								data-options="required:true,validType:'email'"
								missingMessage="请输入有效的电子邮件地址，如example@szlanyou.com"
								invalidMessage="请输入有效的电子邮件地址，如example@szlanyou.com" />
						</div></li>
					<li><label for="orgId" class="label">所属部门：</label>
						<div class="input_con">
							<input type="text" name="orgId" id="orgId" class="text"
								tabindex="12" />
						</div></li>

					<li><label for="empNo" class="label">工号：</label>
						<div class="input_con">
							<input class="easyui-validatebox text" type="text" name="empNo"
								id="empNo" tabindex="7"
								data-options="required:true,validType:'length[1,20]'"
								missingMessage="工号不能为空，且20个字符以内！" />
						</div></li>
					<li id="exeTimeOnDay">
						<label class="label">定时发送邮件：</label><span>每天</span>
						<select id="comboxExecutionExeTimeOnDay" class="easyui-combobox" name="dept" style="width:50px;">
							<option value="0">0</option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
							<option value="6">6</option>
							<option value="7">7</option>
							<option value="8">8</option>
							<option value="9">9</option>
							<option value="10">10</option>
							<option value="11">11</option>
							<option value="12">12</option>
							<option value="13">13</option>
							<option value="14">14</option>
							<option value="15">15</option>
							<option value="16">16</option>
							<option value="17">17</option>
							<option value="18">18</option>
							<option value="19">19</option>
							<option value="20">20</option>
							<option value="21">21</option>
							<option value="22">22</option>
							<option value="23">23</option>
						</select>
						<span>时接收异常邮件</span>
					</li>
					<li><label for="remark" class="label">备注：</label>
						<div class="input_con">
							<input type="text" id="remark" name="remark"
								class="easyui-validatebox text" tabindex="13"
								data-options="validType:'maxLength[100]'" />
						</div></li>
				</ul>
			</div>
		</form>
		<div id="buttons" class="button_con">
			<a href="javascript:void(0)" onclick="onSave()"
				class="easyui-linkbutton" id="instance_save" iconCls="icon-ok"
				plain="true" tabindex="14">保存</a> <a href="javascript:void(0)"
				onclick="rePage()" class="easyui-linkbutton" id="cancalBtn"
				iconCls="icon-cancel" plain="true" tabindex="15">取消</a>
		</div>
	</div>
	<!--选择所属系统-->
	<div class="easyui-window" id="system_selection" title="系统选择">
		<div class="search-con">
			<label for="systemName" style="margin-left: 15px;">名称：</label> <input
				id="systemName" name="systemName" class="text" style="width: 98px;" />
			<button id="searchNode" name="searchNode" style="width: 50px;"
				class="default_btn">定位</button>
			<button id="ensureSelect" name="ensureSelect" style="width: 50px;"
				class="default_btn">确定</button>
		</div>
		<div class="tree_con">
			<ul id="tt"></ul>
		</div>
	</div>


	<!--查看所属系统-->
	<div class="easyui-window" id="system_show" title="接口选择">
		<div class="tree_con">
			<ul id="sys_show_tt"></ul>
		</div>
	</div>

	<div id="winEdit1" class="easyui-window" title="用户授权"
		style="width: 430px; height: auto; top: 20px"
		data-options="iconCls:'icon-save',modal:true,minimizable:false,maximizable:false,collapsible:false">
		<form id="authForm" method="post">
			<div class="popup_con">

				<ul>
					<li class="li_col"><label for="userCode1" class="label">账号：</label>
						<div class="input_con">
							<input id="userId" name="userId" type="hidden" /> <input
								id="userCode1" name="userCode" class="text" readonly="readonly" />
						</div></li>
					<li class="li_col"><label for="assignedRoles" class="label">分配角色：</label>
						<div class="input_con">
							<input class="text" type="text" name="assignedRoles"
								id="assignedRoles" />
						</div></li>
					<li class="li_col"><label for="system" class="label">所属系统：</label>
						<div class="input_con">
							<input id="strFieldSystems" name="strFieldSystems" type="hidden" />
							<input id="system" name="system" type="text" class="text"
								readonly="readonly" />
							<button style="width: 50px; display: inline" class="default_btn"
								id="selSystemBtn">选择</button>
						</div></li>
					<li class="li_col"><label for="remark" class="label">备&nbsp;&nbsp;注：</label>
						<div class="input_con">
							<textarea id="remark" name="remark" rows="4"
								style="width: 200px; padding: 3px;" class="easyui-validatebox"
								data-options="validType:'maxLength[100]'"></textarea>
						</div></li>
				</ul>
			</div>
		</form>
		<div id="buttons1" class="button_con">
			<a href="javascript:void(0)" onclick="onSave1()"
				class="easyui-linkbutton" id="instance_save1" iconCls="icon-ok"
				plain="true">保存</a> <a href="javascript:void(0)"
				onclick="onCancleEdit()" class="easyui-linkbutton" id="cancal"
				iconCls="icon-cancel" plain="true">取消</a>
		</div>
	</div>
	</div>
	<!--导入-->
	<div id="import_link" title="导入">
		<div class="import_con">
			<form id="import_form" method="post"
				action="/api/importData/user/userUpload"
				enctype="multipart/form-data">
				<label>文件地址：</label> <input type="text" id="fileName"
					name="fileName" class="text" readonly="readonly" />
				<button class="default_btn" id="selFileBtn" style="display: inline;">浏览</button>
				<input type="file" name="file" id="file" accept=".xls,.xlsx" />
			</form>
		</div>
		<p style="text-align: center;">
			温馨提示：支持导入的文件格式为.xls和.xlsx<a
				href="../../assets/importDataTempl/用户管理导入模板.xlsx" class="dl-link">下载用户管理导入模板</a>
		</p>
		<div id="buttons_inport" class="button_con">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				id="start-import" onclick="startImport();" iconCls="icon-ok"
				plain="true">确定导入</a>
		</div>
	</div>
	<script type="text/javascript" src="/webjars/json3/3.3.2/json3.min.js"></script>
	<script type="text/javascript"
		src="../../js/jquery-easyui-1.4.3/jquery.min.js"></script>
	<script type="text/javascript"
		src="../../js/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
	<script type="text/javascript"
		src="../../js/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../../js/ajaxfileupload.js"></script>

	<script type="text/javascript" src="../../js/cook/constants.js"></script>
	<script type="text/javascript" src="../../js/cook/FormValidate.js"></script>
	<script type="text/javascript" src="../../js/cook/public.js"></script>
	<script type="text/javascript" src="../../js/rsa/security.js"></script>
	<script type="text/javascript" src="../../js/rsa/rsaly.js"></script>
	<script type="text/javascript" src="../../js/passwordStrength-min.js"></script>
	<script type="text/javascript"
		src="../../js/cook/UerManagement/UserManagement.js"></script>
	<script>
function choose_tree()
{
	$('#tt').tree('expandAll');
	if(arrayLi.length == 0 && arrayLiInd == 0)
	{
		var searchVal = $("#systemName").val().toUpperCase(); 
		var row = $('#tt li .tree-node');  
		var rowcolumn = $('#tt li .tree-node > .tree-title');  
		var i = 0, j = 0;
		var offsetC = 0
		row.removeClass('tree-node-selected');  
		rowcolumn.each(function (column) {  
			var matchVal = $(this).text(); 
			if(matchVal.indexOf(searchVal) != -1)
			{
				i++;
				var panel_top = parseInt($(this).parents(".panel").css("top"), 10);
				
				if(i <= 1)
				{
					$(this).parent().addClass('tree-node-selected'); 
					var top = $(".tree_con").scrollTop() + $(this).offset().top - 76 - panel_top;
					$(".tree_con").scrollTop(top);
					arrayLiInd = 1;
				}			
				arrayLi.push([matchVal,$(".tree_con").scrollTop() + $(this).offset().top - 76 - panel_top]);
				
			}
			}); 
		}else
		{
			var rowcolumn = $('#tt li .tree-node > .tree-title'); 
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');
			
			if(arrayLiInd <  arrayLi.length)
			{
				rowcolumn.each(function (column) {  
					var matchVal = $(this).text(); 
					if(matchVal == arrayLi[arrayLiInd][0])
					{
						$(this).parent().addClass('tree-node-selected'); 
						$(".tree_con").scrollTop(arrayLi[arrayLiInd][1]);
						arrayLiInd++;
						return false;
					}
				});
			}else
			{
				//arrayLi = [];
				arrayLiInd = 0;
				$(".tree_con").scrollTop(0);
				choose_tree();
			}
		}
}

$("#ensureSelect").click(function (e) {
	var checkedNodes = $("#tt").tree("getChecked");
	var selectSystems = "";
	var systemsName = "";
	for(var i = 0, len = checkedNodes.length; i < len; ++i)
	{
		var tempNode = checkedNodes[i];
		if(tempNode.nodeType != "fieldSystem")
		{
			continue;
		}
		selectSystems += (selectSystems != ""? ",":"") + tempNode.id;
		systemsName += (systemsName != ""? ",":"") + tempNode.text;
	}
	$("#strFieldSystems").val(selectSystems);
	$("#system").val(systemsName);
	$('#system_selection').window('close');	
});

function onCancleEdit(){
	$('#winEdit1').window('close');
}
//初始化加载页面
$(document).ready(function(){
	
	$("#searchNode").click(function (e) { 
		if($("#systemName").val() != '')
		{
			choose_tree();
		}
		else
		{
			$(".systemName").val("");
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');
			$(".tree_con").scrollTop(0);
		}
	});
	
	$("#systemName").bind('input propertychange', function() {
		arrayLi = [];
		arrayLiInd = 0;
		if($("#systemName").val() != '')
		{
			choose_tree();
		}else
		{
			$("#ff input").val("");
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');
			$(".tree_con").scrollTop(0);
		}
	});
	$(document , "#systemName").keyup(function(event){
	  if(event.keyCode == 8){
	    $("#searchNode").trigger("click");
	  }
	});
	$(document , "#systemName").keyup(function(event){
	  if(event.keyCode ==13){
	    $("#searchNode").trigger("click");
	  }
	});
	
	
	$('#winEdit1').window('close');
	//接口选择
	$('#system_selection').window({
		width:310,
		height:355,
		modal:true,
		minimizable:false,
		maximizable:false,
		collapsible:false,
		onClose: function () {
			$("#tt").html("");
		}
	});
	$('#system_selection').window('close');  //关闭窗口
	
	//查看系统
	$('#system_show').window({
		width:260,
		height:355,
		modal:true,
		title:"所属系统",
		minimizable:false,
		maximizable:false,
		collapsible:false
	});
	$('#system_show').window('close');  //关闭窗口
	$('#system_selection').window({
		width:310,
		height:355,
		modal:true,
		minimizable:false,
		maximizable:false,
		collapsible:false,
		onClose: function () {
			$("#tt").html("");
		}
	});
	$('#system_selection').window('close');  //关闭窗口
	
	//查看系统
	$('#system_show').window({
		width:260,
		height:355,
		modal:true,
		title:"所属系统",
		minimizable:false,
		maximizable:false,
		collapsible:false
	});
	$('#system_show').window('close');  //关闭窗口
	
	$('#assignedRoles').combobox({
		editable: false,
		url: BASE_URL_ROLES + '?v=' + Date.parse(new Date()),
		valueField: 'id',
	    textField: 'roleName',
	    method:'get',
		onSelect: function(record) {
			$("#assignedRoles").val(record.id);
			if(record.id == "0") //管理员角色，默认拥有所有系统
			{
				$("#selSystemBtn").fadeOut();
				$("#system").val("管理员拥有所有系统");
			}
			else
			{
				$("#selSystemBtn").fadeIn();
				$("#system").val(g_currSystemsStr);
			}
			//console.log(record);
		},
	    loadFilter:function(data){
	    	return data._embedded.roles;
	    },
		onLoadSuccess: function() {
			if(!$("#assignedRoles").val())
			{
				var dataList = $("#assignedRoles").combobox("getData");
				var defaultId = dataList[0].id;
				for(var i = 0; i < dataList.length; ++i)
				{
					if(dataList[i].roleName == "接口运维者")
					{
						defaultId = dataList[i].id;
						break;
					}
				}
				$("#assignedRoles").combobox("select",defaultId);
			}
			else
			{
				$("#assignedRoles").combobox("select",$("#assignedRoles").val());
			}
		}
	});
});
//点击分配打开用户授权修改页面
function onOpenEdit(rowIndex) {
	var rowData = $('#datagrid').datagrid('getRows')[parseInt(rowIndex, 10)];
	$.ajax({
		type: "get",
		url: BASE_URL_USER_SEARCH + "/getFieldSystemRoot?id="+rowData.id,
		dataType:"json",/* 
		async:false, */
		contentType: "application/json",
		success: function(data) {
			//fieldSystems = data;
			reBackData(rowData,data);
		},
		error: function() {
			$.messager.alert('错误','<p>服务异常，修改用户授权信息失败，请稍后重试!</p>','error');
		}
	});	
	
}

//点击分配后要回显用户相关数据
function reBackData(rowData,data){
	$("#userId").val(rowData.id);
	$("#userCode1").val(rowData.userCode);
	var systemsInfo = getSystemsStrFromSyslist(data);
	g_currSystemsStr = systemsInfo.names;
	$("#strFieldSystems").val(systemsInfo.ids);
	$("#system").val(systemsInfo.names);
	$("#remark").val(rowData.remark);

	$('#assignedRoles').combobox('clear');
	if(window.parent.g_currUserCode == rowData.userCode && rowData.roleId == "0")
	{
		$('#assignedRoles').combobox({
			disabled: true,
			onBeforeLoad: function() {
				$("#assignedRoles").val(rowData.roleId);
			},
			url: BASE_URL_ROLES + '?v=' + Date.parse(new Date())
		});
	}
	else
	{
		$('#assignedRoles').combobox({
			disabled: false,
			onBeforeLoad: function() {
				$("#assignedRoles").val(rowData.roleId);
			},
			url: BASE_URL_ROLES + '?v=' + Date.parse(new Date())
		});
	}
	
	$("#authForm").form("validate");
	$('#winEdit1').window('open');
}

//通过领域系统对象数组转成系统字符串
function getSystemsStrFromSyslist(fieldSystemsArr) {
	var systemsStr = "";
	var systemIdsStr = "";
	for(var i = 0, len=fieldSystemsArr.length; i < len; ++i)
	{
		if(!fieldSystemsArr[i])
		{
			continue;
		}
		var fieldName = fieldSystemsArr[i].fieldName;
		var systemName = fieldSystemsArr[i].fieldSystemName;
		systemIdsStr += (systemIdsStr == ""? "":",") + fieldSystemsArr[i].fieldSystemId;
		systemsStr += systemName + (i == len-1? "":",");
	}
	return {
		ids:systemIdsStr,
		names:systemsStr
	};
}

//通过字符串获取系统列表
function getSystemListFromStr(fieldSystemsStr) {
	if(!fieldSystemsStr)
	{
		return [];
	}
	var fieldSystemList = fieldSystemsStr.split(",");
	var systemList = [];
	for(var i = 0, len=fieldSystemList.length; i < len; ++i)
	{
		if(!fieldSystemList[i])
		{
			continue;
		}
		var systemName = fieldSystemList[i].split("-")[1];
		if(systemName)
		{
			systemList.push(systemName);
		}
	}
	return systemList;
}

//通过字符串获取构造领域系统的树节点信息
function getFieldSystemNodesFromStr(fieldSystemsStr) {
	if(!fieldSystemsStr)
	{
		return [];
	}
	var fieldSystemList = fieldSystemsStr.split(",");
	var fieldList = [];
	var systemNodeList = [];
	for(var i = 0, len=fieldSystemList.length; i < len; ++i)
	{
		if(!fieldSystemList[i])
		{
			continue;
		}
		var fieldName = fieldSystemList[i].split("-")[0];
		var systemName = fieldSystemList[i].split("-")[1];
		if(fieldName)
		{
			var tempNode = {};
			var j = 0;
			for(; j < fieldList.length; ++j)
			{
				if(fieldList[j].text == fieldName)
				{
					if(systemName)
					{
						fieldList[j].children.push({
							text:systemName,
							children:[],
							nodeType:"fieldSystem"
						});
					}
					break;
				}
			}
			if(j == fieldList.length)
			{
				tempNode.text = fieldName;
				tempNode.nodeType = "field";
				tempNode.children = [];
				if(systemName)
				{
					tempNode.children.push({
						text:systemName,
						children:[],
						nodeType:"fieldSystem"
					});
				}
				fieldList.push(tempNode);
			}
		}
		
	}
	return fieldList;
}

//通过领域系统对象数组转换成树节点信息
function getFieldSystemNodesFromArr(fieldSystemsArr) {
	if(!fieldSystemsArr)
	{
		return [];
	}
	var fieldNodes = [];
	for(var i = 0, len=fieldSystemsArr.length; i < len; ++i)
	{
		if(!fieldSystemsArr[i])
		{
			continue;
		}
		var fieldName = fieldSystemsArr[i].fieldName;
		var systemName = fieldSystemsArr[i].fieldSystemName;
		if(fieldName)
		{
			var tempNode = {};
			var j = 0;
			for(; j < fieldNodes.length; ++j)
			{
				if(fieldNodes[j].text == fieldName)
				{
					if(systemName)
					{
						fieldNodes[j].children.push({
							text:systemName,
							children:[],
							nodeType:"fieldSystem"
						});
					}
					break;
				}
			}
			if(j == fieldNodes.length)
			{
				tempNode.text = fieldName;
				tempNode.nodeType = "field";
				tempNode.children = [];
				if(systemName)
				{
					tempNode.children.push({
						text:systemName,
						children:[],
						nodeType:"fieldSystem"
					});
				}
				fieldNodes.push(tempNode);
			}
		}
	}
	return fieldNodes;
}

//显示所属系统
function onShowDetail(rowIndex) {
	var rowData = $('#datagrid').datagrid('getRows')[parseInt(rowIndex, 10)];
	$.ajax({
		type: "get",
		url: BASE_URL_USER_SEARCH + "/getFieldSystemRoot?id="+rowData.id,
		dataType:"json",
		contentType: "application/json",
		success: function(data) {
			//fieldSystems = data;
			
			var fieldSystemsNodes = getFieldSystemNodesFromArr(data);
			$("#sys_show_tt").tree("loadData", fieldSystemsNodes);
			$("#sys_show_tt > li > ul > li > .tree-node > .tree-file").css("background","url('../../images/st_folder.png') no-repeat 2px 2px");
			$("#system_show").window('setTitle',rowData.userCode + '所属系统');
			$('#system_show').window('open');
		},
		error: function() {
			$("#instance_save").linkbutton("enable");
			$("#instance_save .l-btn-text").text("保存");
			$.messager.alert('错误','<p>服务异常，修改用户授权信息失败，请稍后重试!</p>','error');
		}
	});		
}

function setChecked(sysName) {
	if(!sysName)
	{
		return;
	}
	$("#tt li .tree-node").each(function(){
		if($(".tree-title", $(this)).text() == sysName)
		{
			$('#tt').tree('check', this);
			return false;
		}
	});
	
}

function setCheckedList(sysNameArr)
{
	if(sysNameArr && sysNameArr.length)
	{
		for(var i = 0, len = sysNameArr.length; i < len; ++i)
		{
			setChecked(sysNameArr[i]);
		}
	}
}

function choose_tree()
{
	$('#tt').tree('expandAll');
	if(arrayLi.length == 0 && arrayLiInd == 0)
	{
		var searchVal = $("#systemName").val().toUpperCase(); 
		var row = $('#tt li .tree-node');  
		var rowcolumn = $('#tt li .tree-node > .tree-title');  
		var i = 0, j = 0;
		var offsetC = 0
		row.removeClass('tree-node-selected');  
		rowcolumn.each(function (column) {  
			var matchVal = $(this).text(); 
			if(matchVal.indexOf(searchVal) != -1)
			{
				i++;
				var panel_top = parseInt($(this).parents(".panel").css("top"), 10);
				
				if(i <= 1)
				{
					$(this).parent().addClass('tree-node-selected'); 
					var top = $(".tree_con").scrollTop() + $(this).offset().top - 76 - panel_top;
					$(".tree_con").scrollTop(top);
					arrayLiInd = 1;
				}			
				arrayLi.push([matchVal,$(".tree_con").scrollTop() + $(this).offset().top - 76 - panel_top]);
				
			}
			}); 
		}else
		{
			var rowcolumn = $('#tt li .tree-node > .tree-title'); 
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');
			
			if(arrayLiInd <  arrayLi.length)
			{
				rowcolumn.each(function (column) {  
					var matchVal = $(this).text(); 
					if(matchVal == arrayLi[arrayLiInd][0])
					{
						$(this).parent().addClass('tree-node-selected'); 
						$(".tree_con").scrollTop(arrayLi[arrayLiInd][1]);
						arrayLiInd++;
						return false;
					}
				});
			}else
			{
				//arrayLi = [];
				arrayLiInd = 0;
				$(".tree_con").scrollTop(0);
				choose_tree();
			}
		}
}

$("#selSystemBtn").click(function(e) {
	//if(treeData==null){
		$("#tt").tree({
			url:BASE_URL_TREE + '/getFieldSystemsForEasyUiTree' + '?v=' + Math.random(),
			method: "get",
			lines:false,
			async:false,
			checkbox: true,
			loadFilter: function(data,parent) {
				treeData = [{text:"全部", children:data, nodeType:"root"}];
				return treeData;
			},
			onLoadSuccess:function()
			{
				$("#tt > li > ul > li > ul > li > .tree-node > .tree-file").css("background","url('../../images/st_folder.png') no-repeat 2px 2px");
				$("#tt > li > ul > li > .tree-node > .tree-file").parent().parent().css("display","none");
				reSetTree();
			},
			onClick:function(node){
				if(node.checked)
				{
					$("#tt").tree("uncheck", node.target);
				}
				else
				{
					$("#tt").tree("check", node.target);
				}
				
				//$("#systemName").val(node.text);
				//choose_tree();
			}
		});
	//}else{
		//reSetTree()
	//}
	
	
	return false;
});

function reSetTree(){
	$('#system_selection').window('open');	
	var txtInterface = $("#system").val().split(",")[0];

	if(txtInterface !== '')
	{
		$("#systemName").val(txtInterface);
		choose_tree();
	}
	else
	{
		$("#systemName").val('');
		$(".tree_con").scrollTop(0);
		var row = $('#tt li .tree-node');  
		row.removeClass('tree-node-selected');
	}
	
	var checkedNodes = $("#tt").tree("getChecked");
	if(checkedNodes)
	{
		$.each(checkedNodes, function(index, node) {
			$("#tt").tree("uncheck", node.target);
		});
	}
	
	var currSystemsStr = $("#system").val();
	if(currSystemsStr != '')
	{
		setCheckedList(currSystemsStr.split(","));
	}
}
function onSave1()
{
	if($("#authForm").form("validate")){
		$("#instance_save").linkbutton("disable");
		$("#instance_save .l-btn-text").text("提交中...");
		var row = $('#datagrid').datagrid('getSelected');
		var newUserInfoJSON = {};
		newUserInfoJSON["roleId"] = $('#assignedRoles').combobox("getValue");
		var fieldSystemsStr = $("#strFieldSystems").val();
		newUserInfoJSON["fieldSystemIds"] = fieldSystemsStr == ""? []:fieldSystemsStr.split(",");
		newUserInfoJSON["remark"] = $("#remark").val();
		newUserInfoJSON["id"] = $("#userId").val();
		$.ajax({
			type: "post",
			url: BASE_URL_USER_CRUD + "/assignRoleAndSystem",
			data: JSON.stringify(newUserInfoJSON),
			contentType: "application/json",
			success: function(result) {
				$("#instance_save").linkbutton("enable");
				$("#instance_save .l-btn-text").text("保存");
				if(result.backValue === true)
				{
					$('#winEdit1').window('close');  //关闭窗口
					$.messager.alert('提示','<p>修改用户授权信息成功!</p>', 'info');
					$("#datagrid").datagrid("reload", BASE_URL_USER_SEARCH + '/findByExample?v=' + Date.parse(new Date()));
					
				}
				else
				{
					$.messager.alert('错误', '<p>' + result.backValue + '</p>','error');
				}
			},
			error: function() {
				$("#instance_save").linkbutton("enable");
				$("#instance_save .l-btn-text").text("保存");
				$.messager.alert('错误','<p>服务异常，修改用户授权信息失败，请稍后重试!</p>','error');
			}
		});
	};
}

</script>
</body>
</html>



